<template lang="html">
  <div class="container" v-loading="loading">
      <div class="search">
          <el-form :inline="true" class="demo-form-inline">
              <el-form-item>
                <el-input class="form_input" v-model="searchText" placeholder="请输入订单编号"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" :disabled="loading" size="small" @click="onSubmit">搜索</el-button>
              </el-form-item>
              <el-form-item>
                <datePicker startEndTime @onFilter="onFilter" />
              </el-form-item>
          </el-form>



          <div class="export_excl">
            <el-button size="small" :disabled="isShutdownAudit" @click="exportExcl" type="primary">导出<i class="el-icon-upload el-icon--right"></i></el-button>
          </div>
      </div>

      <div class="tables">
          <vTable :tableData="tableData" ref="vTable" :tInData="tInData" @onCheckAll="onCheckAll" @onCheck="onCheck">
              <template slot="产品" slot-scope="scope">
                <div class="pro">
                    <div class="pro_image">
                      <img :src="scope.row.picUrl" alt="" />
                    </div>
                    <div class="pro_info">
                      <div class="pro_name">{{scope.row.commodityName}}</div>
                      <div class="num_color">{{scope.row.materialName}}/{{scope.row.color}}/{{scope.row.laceName}}x{{scope.row.commodityNum}}</div>
                      <div class="address">地址：{{scope.row.address}}</div>
                    </div>
                </div>
              </template>
              <template slot="操作" slot-scope="scope">
                <div class="button">
                  <el-button size="mini" type="danger" @click="handleDetail(scope.row)">详情</el-button>
                </div>
              </template>
          </vTable>

          <pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :currentPage="currentPage" :totalPage="totalPage" />
      </div>

  </div>
</template>

<script>
export default {
  data(){
    return {
      loading: false,
      searchText: '',
      date: [],
      year: '',
      month: '',
      day: '',
      tableData: [],
      selectData:[],
      currentPage: 1,
      totalPage: 0,
      pageSize: 10,
      queryId: this.$route.query.id,
      tInData:[
        {
          props: 'orderSublistId',
        },
        {
          props: 'createTime',
        },
        {
          title: '产品',
          width: '350px',
        },
        {
          title: '设计师',
          props: 'designerName',
        },
        {
          title: '销售价格',
          props: 'commodityPrice',
        },
        {
          title: '成交价格',
          props: 'successPrice',
        },
        {
          title: '结算价格',
          props: 'realPrice',
        },
        {
          title: '操作',
        },
      ],
    }
  },
  computed:{
    isShutdownAudit:function(){
        return this.selectData.length == 0?true:false;
    }
  },

  created(){
    this.queryId = this.$route.query.id;
    this.getServeData();
  },
  methods: {
    getServeData(){
      this.loading = true;
      this.$http.selectDataStatsPayMemberDetailPage({
        mId: this.queryId,
        query: this.searchText,
        startTime: (this.date&&this.date[0]) || '',
        endTime: (this.date&&this.date[1]) || '',
        dayTime: this.day,
        monthTime: this.month,
        yearTime: this.year,
        pageNumber: this.currentPage,
        pageSize: this.pageSize
      })
      .then(res=>{
        this.loading = false;
        this.tableData = res.data.rows;
        this.tableData.forEach(item=>{
          if(item.createTime){
            item.createTime = this.$parent.formatTime(item.createTime);
          }
        });
        this.totalPage = res.data.total;
        this.pageSize = res.data.pageSize;
      });
    },
    exportsAPI(ids){
      ids && (
        this.$http.dataStatsOrderExportOrder({orderSublistIds: ids})
      )

    },
    onFilter(e){
      this.date = [];
      this.year = '';
      this.month = '';
      this.day = '';
      switch (e.key) {
        case 1: this.day = e.val; break;
        case 2: this.month = e.val; break;
        case 3: this.year = e.val; break;
        case 4: this.date = [...e.val]; break;
      }
      this.onSubmit()
    },
    handleDetail(e){
      this.$router.push({ path: '/statistics/sales_statistics/user_orders/detail', query: {id: e.orderSublistId,type:'2'}});
    },
    onCheckAll(val){
      if(val.status){
        this.selectData = [];
        this.tableData.forEach((item,index)=>{
          this.selectData.push(item);
        })
      }else{
        this.selectData = [];
      }
    },
    onCheck(val){
      if(val.status){
        this.tableData.forEach((item,index)=>{
          if(val.index == index){
            this.selectData.push(item);
          }
        })
      }else{
        this.selectData = this.selectData.filter(arr=>(arr.id!==this.tableData[val.index].id))
      }
    },

    onSubmit(){
      this.handleCurrentChange(1);
    },
    handleSizeChange(e){
      this.pageSize = e;
      this.handleCurrentChange(1);
    },
    handleCurrentChange(e){
      this.currentPage = e;
      this.getServeData();
    },

    exportExcl(){
      let aId = [];
      this.selectData.forEach(item=>{aId.push(item.orderSublistId)});
      this.$confirm('确定要导出吗？').then(()=>{
        this.exportsAPI(aId.join(','));
      }).catch(e=>0);
    }
  }
}
</script>

<style lang="css" scoped>
.active{
  color: #FFF;
  background-color: #409EFF;
  border-color: #409EFF;
}
.search{
  display: flex;
  position: relative;
}
.export_excl{
  position: absolute;
  right: 0
}
</style>
